<script>
  //publishAdvertVal();
  initSelectPicker();
  initAjaxImageUpload(10, 'advert/publish/upload', 'advert_images');
</script>
<div class="col-sm-9 content-right">
  <ol class="breadcrumb">
    <li><a class="route-controller" href="<?php echo site_url('home'); ?>">Home</a></li>
    <li>Publish Advert</li>
  </ol>
  <h3>Publish an Advert</h3>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent sit amet porta eros, eget facilisis arcu. Duis condimentum fermentum enim, ac rutrum erat venenatis vel. Morbi pharetra viverra faucibus.</p>
  <hr>
  <form role="form" id="publish_advert" action="<?php echo site_url('advert/publish?category=' . $category_id); ?>" method="post">
    <div class="panel panel-default">
      <div class="panel-heading">
        <a class="panel-title accordion-toggle" data-toggle="collapse" href="#advert_publish_category">Advert category</a>
      </div>
      <div class="panel-body in" id="advert_publish_category">
        <div class="form-group">
          <label for="advert_category">Category</label>
          <select name="advert_category" id="advert_category" class="form-control" onchange="advertChangeCategory(this);">
            <?php if (!empty($categories)) { ?>
              <?php foreach ($categories as $category) { ?>
                <?php $cat_icon = (!empty($category['category_icon'])) ? $category['category_icon'] : 'fa-certificate'; ?>
                <option value="<?php echo $category['category_id']; ?>" <?php if ($category_id == $category['category_id']) { ?> selected="true" <?php } ?> data-icon="fa <?php echo $cat_icon; ?>"><?php echo $category['category_name']; ?></option>
              <?php } ?>
            <?php } else { ?>
              <option value="0">-- Select Category --</option>
            <?php } ?>
          </select>
        </div>
      </div>
    </div>
    <div class="panel panel-default" id="advert_details_basic">
      <div class="panel-heading">
        <a class="panel-title accordion-toggle" data-toggle="collapse" href="#advert_details_basic_body">Advert Basic Details</a>
      </div>
      <div class="panel-body in" id="advert_details_basic_body">
        <div class="form-group">
          <label for="advert_type">Type</label>
          <select name="advert_type" id="advert_type" class="form-control">
            <option value="1" <?php if ($type == 1) { ?> selected="true" <?php } ?> data-icon="fa fa-briefcase">Trade / Sale</option>
            <option value="2" <?php if ($type == 2) { ?> selected="true" <?php } ?> data-icon="fa fa-shopping-cart">Need / Wanted</option>
          </select>
        </div>
        <div class="form-group">
          <label for="advert_item">Item</label>
          <select name="advert_item" id="advert_item" class="form-control">
            <?php if (!empty($items)) { ?>
              <?php foreach ($items as $item) { ?>
                <option value="<?php echo $item['item_id']; ?>"><?php echo $item['item_name']; ?></option>
              <?php } ?>
            <?php } else { ?>
              <option value="0">-- No Items --</option>
            <?php } ?>
          </select>
        </div>
        <div class="form-group">
          <label for="advert_item_type">Item type</label>
          <select name="advert_item_type" id="advert_item_type" class="form-control">
            <?php if (!empty($item_types)) { ?>
              <?php foreach ($item_types as $item_type) { ?>
                <option value="<?php echo $item_type['item_type_id']; ?>"><?php echo $item_type['item_type_name']; ?></option>
              <?php } ?>
            <?php } else { ?>
              <option value="0">-- No Item Types --</option>
            <?php } ?>
          </select>
        </div>
        <div class="form-group  <?php if (form_error('advert_title')) { ?> has-error <?php } ?>">
          <label for="heading">Title</label>
          <input type="text" name="advert_title" id="advert_title" class="form-control" id="heading" placeholder="Eg: Apple iPad mini 32GB + Wi-Fi + 1 Year Warranty" value="<?php echo set_value('advert_title'); ?>" maxlength="250"/>
          <?php if (form_error('advert_title')) { ?>
            <small class="help-block"><?php echo form_error('advert_title'); ?></small>
          <?php } ?>
        </div>
        <div class="form-group">
          <label for="text">Description</label>
          <textarea id="text" name="advert_description" id="advert_description" class="form-control" rows="8" style="resize: vertical;" placeholder="Eg: "></textarea>
        </div>
        <div class="form-group">
          <label>Deal</label>
          <select name="advert_price_type" id="advert_price_type" class="form-control" onchange="setPriceValue();">
            <option value="1" data-icon="fa fa-money">Fixed Price</option>
            <option value="2" data-icon="fa fa-money">Negotiable Price</option>
            <option value="3" data-icon="fa fa-exchange">Exchange</option>
            <option value="4" data-icon="fa fa-bullseye">Free</option>
          </select>
        </div>
        <div class="form-group" id="advert_price_section">
          <label>Amount / Price</label>
          <div class="input-group">
            <input type="text" name="advert_price_value" id="advert_price_value" class="form-control" maxlength="8" placeholder="Amount" style="width: 500px;"/>
            <select name="advert_price_currency" id="advert_price_currency" class="form-control">
              <option value="1" data-icon="fa fa-dollar">Dollar</option>
              <option value="2" data-icon="fa fa-euro">Euro</option>
              <option value="3" data-icon="fa fa-gbp">Pound</option>
              <option value="4" data-icon="fa fa-rupee" selected="true">Rupee</option>
              <option value="5" data-icon="fa fa-yen">Yen</option>
            </select>
          </div>
        </div>
        <div class="form-group">
          <label for="zip">Zip / Pin Code</label>
          <input type="text" class="form-control" id="advert_zip_code" name="advert_zip_code" placeholder="Zip / Pin Code"/>
        </div>
        <div class="form-group">
          <label for="zip">Locality</label>
          <input type="text" class="form-control" id="advert_locality" name="advert_locality" placeholder="Locality"/>
        </div>
      </div>
    </div>
    <div class="panel panel-default" id="advert_details_images">
      <div class="panel-heading">
        <a class="panel-title accordion-toggle" data-toggle="collapse" href="#advert_details_images_body">Advert Images</a>
        <span class="text-muted pull-right">Choose upto 10 images</span>
      </div>
      <div class="panel-body in" id="advert_details_images_body">
        <div class="form-group">
          <label for="heading">Image Files</label>
          <input type="hidden" name="advert_images_uploaded" id="advert_images_uploaded" value=""/>
          <div class="fileinput fileinput-new input-group text-center" data-provides="fileinput">
            <div class="form-control" data-trigger="fileinput"><i class="glyphicon glyphicon-file fileinput-exists"></i> <span class="fileinput-filename"></span></div>
            <span class="input-group-addon btn btn-default btn-file"><span class="fileinput-new">Select file</span><span class="fileinput-exists">Change</span><input type="file" multiple="true" id="advert_images_file" name="advert_images_file" onchange="removeImgIds('advert_images');"/></span>
            <span class="input-group-addon btn btn-default fileinput-exists" data-dismiss="fileinput" onclick="removeImgIds('advert_images');">Remove</span>
          </div>
        </div>
        <div class="form-group" id="advert_images_form_group">
          <div class="progress progress-striped">
            <div id="advert_images_progress" class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width: 0px;">
              <span class="sr-only"></span>
            </div>
          </div>
          <div class="text-muted" id="advert_images_message">0 files selected</div>
        </div>
      </div>
    </div>
    <div class="panel panel-default" id="advert_details_advanced">
      <div class="panel-heading">
        <a class="panel-title accordion-toggle collapsed" data-toggle="collapse" href="#advert_details_advanced_body">Advert Advance Details</a>
        <span class="text-muted pull-right">Tell more about your advert</span>
      </div>
      <div class="panel-body collapse" id="advert_details_advanced_body">
        <div class="form-group">
          <label for="zip">Year / Model</label>
          <input type="text" class="form-control" id="advert_year_model" name="advert_year_model" placeholder="Year / Model" maxlength="4"/>
        </div>
        <div class="form-group">
          <label for="advert_brand">Brand</label>
          <select name="advert_brand" id="advert_brand" class="form-control">
            <?php if (!empty($brands)) { ?>
              <?php foreach ($brands as $brand) { ?>
                <option value="<?php echo $brand['brand_id']; ?>"><?php echo $brand['brand_name']; ?></option>
              <?php } ?>
            <?php } else { ?>
              <option value="0">-- No Brand --</option>
            <?php } ?>
          </select>
        </div>
        <div class="form-group">
          <label for="advert_brand_model">Brand Model</label>
          <select name="advert_brand_model" id="advert_brand_model" class="form-control">
            <?php if (!empty($brand_models)) { ?>
              <?php foreach ($brand_models as $brand_model) { ?>
                <option value="<?php echo $brand_model['brand_model_id']; ?>"><?php echo $brand_model['brand_model_name']; ?></option>
              <?php } ?>
            <?php } else { ?>
              <option value="0">-- No Brand Model --</option>
            <?php } ?>
          </select>
        </div>
      </div>
    </div>
    <div class="well clearfix">
      <a href="<?php echo site_url('advert/publish'); ?>" class="route-controller confirm-action btn btn-default pull-left" confirm="Are you sure to discard this advert ?">Cancel</a>
      <button type="submit" class="btn btn-danger pull-right">Continue</button>
    </div>
  </form>
</div>